package com.henghong.CouponDemo.controller;

import com.henghong.CouponDemo.result.Result;
import com.henghong.CouponDemo.service.MaintenanceService;
import com.henghong.CouponDemo.vo.MaintenanceVO;
import com.henghong.CouponDemo.vo.SearchCouponVO;
import com.henghong.CouponDemo.vo.UsageHistoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * created by bishukai on 2025/02/24
 */
@RestController
@RequestMapping("/maintenance")
@Slf4j
@Api(tags = "优惠券番号详情接口")
public class MaintenanceController {

    @Autowired
    private MaintenanceService maintenanceService;

    @GetMapping("/getCouponMaintenanceInfo")
    @ApiOperation(value = "M01からクーポン番号詳細情報取得")
    public Result<MaintenanceVO> getCouponMaintenanceInfo(String couponNo) {
        log.info("getCouponMaintenanceInfo couponNo:{}", couponNo);
        MaintenanceVO maintenanceVO = maintenanceService.getCouponMaintenanceInfo(couponNo);
        if (maintenanceVO == null) {
            return Result.error("ERROR002");
        }
        return Result.success(maintenanceVO);
    }

    @GetMapping("/getUsageHistory")
    @ApiOperation(value = "個別クーポンIDより利用履歴データを取得")
    public Result<UsageHistoryVO> getUsageHistory(String eachCouponId) {
        log.info("getUsageHistory eachCouponId:{}", eachCouponId);
        UsageHistoryVO usageHistoryVO = maintenanceService.getUsageHistory(eachCouponId);
        if (usageHistoryVO == null) {
            return Result.error("ERROR002");
        }
        return Result.success(usageHistoryVO);
    }

}
